package cn.zptc.web;

import cn.zptc.dao.impl.FavoriteDaoImpl;
import cn.zptc.entity.Favorite;
import cn.zptc.entity.FavoriteCategory;
import cn.zptc.service.FavoriteService;
import cn.zptc.service.impl.FavoriteServiceImpl;
import com.alibaba.fastjson.JSON;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@WebServlet("/client/delMyFavorite")
public class DelMyFavoriteServlet extends HttpServlet {

    private FavoriteService favoriteService;

    @Override
    public void init() throws ServletException {
        super.init();

        favoriteService = new FavoriteServiceImpl(new FavoriteDaoImpl());
    }

    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {

        try {
            int favoriteId = Integer.parseInt(req.getParameter("favoriteId"));
            //todo:假定userid=1
            int i=favoriteService.delFavorite(favoriteId,1);
            resp.sendRedirect("my_favorite_list.html");

        } catch (SQLException e) {
            throw new RuntimeException(e);
        }
    }
}
